{extend name="base" /}
<!-- page specific plugin styles -->
{block name="inline-styles"}
{/block}
<!-- PAGE CONTENT BEGINS -->
{block name="content"}
<div class="page js_show">
    <div class="page__bd">
        <form class="weui-cells weui-cells_form weui-cells_checkbox" id="ajaxForm">

            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" name="name" placeholder="请输入姓名">
                </div>
            </div>

            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">联系电话</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="tel" name="tel" placeholder="请输入手机号">
                </div>
            </div>

            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">所在地址</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" id="city-picker" name="addrvalue" type="text" value="北京 北京市 东城区" readonly="">
                </div>
            </div>

            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">详细地址</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" name="addr" placeholder="请填写详细地址">
                </div>
            </div>
            <!-- <label class="weui-cell weui-check__label" for="s11">
                <div class="weui-cell__hd">
                    <input type="checkbox" class="weui-check" name="ifdefault" id="s11" checked="checked" value="1">
                    <i class="weui-icon-checked"></i>
                </div>
                <div class="weui-cell__bd">
                    <p>设为默认地址</p>
                </div>
            </label> -->
        </form>

        <div class="weui-btn-area">
            <a class="weui-btn weui-btn_primary" href="javascript:;" id="showToast">保存</a>
        </div>
    
    </div>
    <div class="page__ft">
        <div class="weui-footer weui-footer_fixed-bottom">
            <p class="weui-footer__links">
                <a href="javascript:void(0);" class="weui-footer__link">米粒生活</a>
            </p>
            <p class="weui-footer__text">Copyright © 2008-2018 mlilife.com</p>
        </div>
    </div>
</div>
{/block}
<!-- PAGE CONTENT ENDS -->
<!-- inline scripts related to this page -->
{block name="related-scripts"}
<script src="/static/jquery-weui/dist/js/city-picker.min.js"></script>
<script type="text/javascript">
    $("#city-picker").cityPicker({
        title: "请选择所在地"
    });
    $.ajax({
        url: '/api/v1/address/find',
        type: 'GET',
        dataType: 'json',
        data:{
            id: GetQueryString("id"),
            type:2
        },
    })
    .done(function(json) {
        console.log("success");
        initFormHTML("ajaxForm",json.data);
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
    $("#showToast").click(function(event) {
        /* Act on the event */
        var options={
            url:"/api/v1/address/update",
            type:"POST",
            dataType:"json",
            data:{
                id: GetQueryString("id"),
                type:2
            },
            success: function(json){

                if(json.returnCode==1){
                    $.toast("修改成功", function() {
                       window.location.href = document.referrer;
                    });
                }else{
                    $.toptip(json.returnMsg, 'error');
                }
            }
        };
        $("#ajaxForm").ajaxSubmit(options)
    });
</script>
{/block}